﻿@model MSAcademic.v2.Web.Areas.Admin.Models.Article.ArticleUpdateModel

@{
    ViewBag.Title = "[Uredi] " + Model.Article.Title;
}

<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<script src="~/Areas/Admin/Content/Scripts/View/ArticleUpdate.js"></script>
<script type="text/javascript"> 
    $(function () {
        var boundTags = { };
        @foreach (var tag in Model.BoundTags)
        {
            <text> boundTags["@tag.Id"] = "@tag.Name"; </text>
        }
        msacademic.multipleItemSelector($('.tagsMultipleItemSelector'), boundTags, $('#TagsToBindCsv'));

        var boundSubsections = {};       
        @foreach(var subSection in Model.BoundSubSections)
        {
            <text> boundSubsections["@subSection.Id"] = "@subSection.Name"; </text>
        }
        msacademic.multipleItemSelector($('.subsectionsMultipleItemSelector'), boundSubsections, $('#SubSectionsToBindCsv'));
    });
</script>

<div class="updateArticle">

    <h2>@Model.Article.Title </h2>

    @using (Html.BeginForm())
    {
        @Html.HiddenFor(x => x.Id)
         
        <div class="clearfix">
            <h3>Naslov teksta</h3>
            @Html.TextAreaFor(x => x.Title)
            @Html.ValidationMessageFor(x => x.Title)
        </div>

        if(Model.CanPublishAndHide)
        {
           <div class="clearfix articleProps">
               <h3>Svojstva članka</h3>
               <div class="clearfix">
                   <label for="IsHidden">Je li tekst skriven?</label>
                   @Html.CheckBoxFor(x => x.IsHidden)
               </div>

               <div class="clearfix">
                   <label for="PublishOnUpdate">Je li tekst objavljen?</label>
                   @Html.CheckBoxFor(x => x.PublishOnUpdate)
               </div>
           
           </div>
        
           <div class="clearfix">
                @if(Model.PublishedOn.HasValue)
                {   <h3>Promijeni datum objave</h3>
                    @Html.TextBoxFor(x => x.PublishedOn)
                }
           </div>
        
           <div class="clearfix">
               <h3> Dodaj tekst u sekciju </h3>
               <div class="tag-cloud-wrapper subsectionsMultipleItemSelector">
               
                   @foreach (var item in Model.ContentSectionsWithSubSections)
                   {
                       <h4>@item.Item1.Name</h4>
                       <ul>
                           @foreach (var subSection in item.Item2)
                           {
                               <li><a data-id="@subSection.Id" class="item"> @subSection.Name </a> </li>
                           }
                       </ul>
                   }
               </div>
           
               @Html.HiddenFor(x => x.SubSectionsToBindCsv)

           </div>
                       
        }

        <div class="clearfix">
            <h3>Označi tekst tagovima</h3>
            <div class="tag-cloud-wrapper tagsMultipleItemSelector">
                <ul>
                @foreach (var tag in Model.AllTags.OrderBy(t => t.Name))
                {
                    <li> <a data-id="@tag.Id" class="item"> @tag.Name </a> </li>
                } 
                </ul>

                @Html.HiddenFor(x => x.TagsToBindCsv)
            </div>
        </div>    
            
        <hr />            
        
        <div class="clearfix">
            <h3>Upravljanje slikama</h3>
            <div class="picture-manager-link">
                <a href="@Url.RouteUrl("UploadArticleFrontPictures", new { articleId = Model.Article.Id  })" target="_blank">
                    <i class="icon-picture"></i> 
                    Otvori urednik slika za ovaj članak
                </a>

                <p>Trenutno odabrana slika:</p>
                <img src="@Model.Article.PictureUrlThumbnail" alt=""/>
            </div>
        </div>
        
        <hr />
        
        <div class="clearfix ckeditor">
            <h3>Kratki tekst</h3>
            @Html.TextAreaFor(x => x.ShortText)
            @Html.ValidationMessageFor(x => x.ShortText)
        </div>
        
        <div class="clearfix ckeditor">
            <h3>Dugi tekst</h3>
            @Html.TextAreaFor(x => x.LongText)
            @Html.ValidationMessageFor(x => x.LongText)
        </div>                
        
        <div class="actions-wrapper clearfix">
            <a href="@Url.RouteUrl("ArticleIndexAdmin")" class="cancel">Odustani</a> 
            <a class="positive submit">Spremi promjene <i class="icon-ok"></i></a>
            <a data-url="@Url.RouteUrl("ArticlePreviewAdmin", new { Model.Id }, Request.Url.Scheme)" class="special preview">Spremi i prikaži promjene <i class="icon-magic"></i></a>
        </div>
                
    }

</div>
